from django.conf.urls.defaults import *
from iptables.models import Rule,Tcp,Udp,Optional,Icmp,Prefixer,Chain

urlpatterns = patterns ('mysite.iptables.views',
	
	(r'^$','index'),
	(r'^rule/add/$','add_rule'),
	(r'^rule/(?P<rule_id>[0-9]+)/add/udp/$','add_udp'),
	(r'^rule/(?P<rule_id>[0-9]+)/$','rule_edit'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/$','add_rule'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/udp/(?P<udp_id>[0-9]+)/$','add_udp'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/udp/$','edit_udp'),
	(r'^rule/(?P<rule_id>[0-9]+)/add/tcp/$','add_tcp'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/tcp/$','edit_tcp'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/tcp/(?P<tcp_id>[0-9]+)/$','add_tcp'),
	(r'(^rule/(?P<rule_id>[0-9]+)/add/extra/$)','add_extra'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/extra/$','edit_extra'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/extra/(?P<extra_id>[0-9]+)/$','add_extra'),
	(r'(^rule/(?P<rule_id>[0-9]+)/add/icmp/$)','add_icmp'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/icmp/$','edit_icmp'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/icmp/(?P<icmp_id>[0-9]+)/$','add_icmp'),
	(r'(^rule/(?P<rule_id>[0-9]+)/add/prefix/$)','add_prefix'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/prefix/$','edit_prefix'),
	(r'^rule/(?P<rule_id>[0-9]+)/edit/prefix/(?P<pref_id>[0-9]+)/$','add_prefix'),
	(r'^rule/logs/$','wrap_log'),
	(r'^rule/show/load/(?P<chain_id>[0-9]*)/$','show_load'),
	(r'^rule/unload/$','unload_rule'),
	(r'^rule/load/$','load_rule'),
	 
	#the chain adding and editing
	(r'^chain/add/$','add_chain'),
	(r'^chain/edit/show/(?P<chain_id>[0-9]+)/$','edit_chain'),
	(r'^chain/edit/(?P<chain_id>[0-9]+)/$','add_chain'),
    
    #the rule order changer
    (r'^rule/up/$','order_up'),
    (r'^rule/down/$','order_down'),
	
	#the chains thing sorting:
	(r'^chain/show/$','show_chains'),
    (r'^rule/default/$','show_sort_chains'),
	(r'^rule/sort/(?P<chain_name>.*)/$','show_sort_chains'),
	
	
	)

info_dict={
	'queryset':Rule.objects.select_related(),
	'paginate_by':6
	
	}

info_chain={
	'queryset':Rule.objects.order_by("parent_chain"),
	'paginate_by':6
	
	
	}

info_target={
	'queryset':Rule.objects.order_by("parent_target"),
	'paginate_by':6
	
	}

info_name={
	'queryset':Rule.objects.order_by("name"),
	'paginate_by':6
	
	}



urlpatterns+=patterns('',
	(r'^rule/show(?P<page>[0-9]*)/$','django.views.generic.list_detail.object_list',dict(info_dict,template_name='rule_table.html')),
	(r'^rule/tcp/(?P<slug>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Tcp,slug_field='parent_rule',template_name="delete.html",post_delete_redirect="/iptables/rule/show/")),
	
	(r'^rule/show/sort/chain/$','django.views.generic.list_detail.object_list',dict(info_chain,template_name='rule_table.html')),
	(r'^rule/show/sort/target/$','django.views.generic.list_detail.object_list',dict(info_target,template_name='rule_table.html')),
	(r'^rule/show/sort/name/$','django.views.generic.list_detail.object_list',dict(info_name,template_name='rule_table.html')),
	
	
	(r'^rule/udp/(?P<slug>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Udp,slug_field='parent_rule',template_name="delete.html",post_delete_redirect="/iptables/rule/show/")),
	
	
	(r'^rule/extra/(?P<slug>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Optional,slug_field='parent_rule',template_name="delete.html",post_delete_redirect="/iptables/rule/show/")),
	
	(r'^rule/icmp/(?P<slug>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Icmp,slug_field='parent_rule',template_name="delete.html",post_delete_redirect="/iptables/rule/show/")),
	
	(r'^rule/prefix/(?P<slug>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Prefixer,slug_field='parent_rule',template_name="delete.html",post_delete_redirect="/iptables/rule/show/")),
	
	
	(r'^rule/(?P<object_id>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Rule,template_name="delete.html",post_delete_redirect="/iptables/rule/show/")),
	
	(r'^chain/(?P<object_id>[0-9]+)/delete/$','django.views.generic.create_update.delete_object',
	dict(model=Chain,template_name="delete.html",post_delete_redirect="/iptables/chain/show/")),
	
	
	
	(r'^giris/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
    	(r'^cikis/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}),
	
	)

urlpatterns += patterns ('',
	
	(r'media/(?P<path>.*)$','django.views.static.serve',{'document_root':'/home/makkalot/django_site/mysite/iptables/template/media'}),  

)
